var express = require('express');
var marked = require('marked');
var https = require('https');
const { response } = require('express');

// 创建当前级路由
var articleRouter = express.Router();


// 路由到下一级
articleRouter.get('/:articleID', (req, res) => {
    articleID = req.params.articleID
    markDownURL = `https://xib-article-markdown.oss-cn-beijing.aliyuncs.com/${articleID}.markdown`
    https.get(markDownURL, (resData) => {
        resData.setEncoding('utf-8')
        var articleContent = ''
        resData.on('data', (data) => {
            articleContent += data
        }).on('end', ()=>{
            res.render('article/INDEX', {
                article : marked(articleContent)
            })
        })
    })

    
})


// 暴露当前级路由
module.exports = articleRouter